package com.weyoung.admin.controller;

import com.weyoung.admin.dto.req.AdminFamilyAddDTO;
import com.weyoung.admin.dto.req.FamilyAddDTO;
import com.weyoung.admin.mapper.FamilyMapper;
import com.weyoung.admin.service.FamilyCultureService;
import com.weyoung.admin.service.FamilyService;
import com.weyoung.common.consatant.result.Result;
import com.weyoung.common.model.entity.FamilyDO;
import com.weyoung.common.model.entity.UserDO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("admin/family")
@Tag(name = "Web端-家族接口")
@Slf4j
@RequiredArgsConstructor
public class FamilyController {

    @Autowired
    private FamilyService familyService;
    private final FamilyCultureService familyCultureService;

    @Autowired
    private FamilyMapper familyMapper;

    /**
     * 获取所有家族列表
     * @return Result
     */
    @GetMapping("/list")
    @Operation(summary = "获取所有家族列表")
    public Result<List<FamilyDO>> list() {
        return Result.success(familyMapper.finList());
    }

    /**
     * 根据家族id查找家族
     * @return Result
     */
    @GetMapping("/getfamilyById")
    @Operation(summary = "根据家族id获取家族信息")
    public Result<FamilyDO> getfamilyById(@RequestParam("id") String id) {
        FamilyDO familyDO = familyService.getById(id);
        return Result.success(familyDO);
    }

    /**
     * 根据家族名查找家族
     * @return Result
     */
    @GetMapping("/getfamilyByName")
    @Operation(summary = "根据家族名获取家族信息（模糊查询）")
    public Result<List<FamilyDO>> getfamilyByName(@RequestParam("name") String name) {

        return Result.success(familyService.getByNmae(name));
    }

    /**
     *
     */
    @PostMapping("/add")
    @Operation(summary = "家族信息新增或修改")
    public Result<FamilyDO> add1(@RequestBody AdminFamilyAddDTO familyAddDTO) {
        familyService.add1(familyAddDTO);
        return Result.success();
    }


    /**
     * 家族信息删除（逻辑删除）
     *@param id
     * @return Void
     *
     * 这里存在问题，逻辑删除完成后，is_deleted 变成1， 但是查找时仍旧能找到（可能是配置的问题）
     */
    @DeleteMapping("/delete1")
    @Operation(summary = "家族信息删除（逻辑删除）")
    public Result<Void> delete1(@RequestParam("id") String id){
        familyMapper.delete1(id);
        return Result.success();
    }

    /**
     * 家族信息删除（彻底删除）
     *@param id
     * @return Void
     */
    @DeleteMapping("/delete2")
    @Operation(summary = "家族信息删除（彻底删除）")
    public Result<Void> delete2(@RequestParam("id") Integer id){
        familyService.removeById(id);
        return Result.success();
    }

    /**
     * 获取家族文化列表
     * @return Result
     */
    @GetMapping("/getFamilyCultureList")
    @Operation(summary = "获取某家族的文化列表")
    public Result getFamilyCultureListById(@RequestParam("familyId") String familyId) {

        return familyCultureService.getFamilyCultureListById(familyId);
    }

    @GetMapping("/getFamilyCulture/{id}")
    @Operation(summary = "查看某家族文化文化详情")
    public Result getFamilyCulture(@PathVariable("id") String id) {
        return familyCultureService.getFamilyCulture(id);
    }

    @PostMapping("/deleteFamilyCultureById")
    @Operation(summary = "删除某家族文化文化详情")
    public Result deleteFamilyCulture(@RequestParam("id") String id) {
        return familyCultureService.deleteFamilyCultureById(id);
    }



}
